package com.gw.detail.service.param.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gw.detail.domain.param.CommonType;
import com.gw.detail.mapper.param.CommonTypeMapper;
import com.gw.detail.service.param.ICommonTypeService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 行政区Service业务层处理
 *
 * @author wangbin
 * @date 2021-04-29
 */
@Service
public class CommonTypeServiceImpl extends ServiceImpl<CommonTypeMapper, CommonType> implements ICommonTypeService {

    /**
     * 查询通用代码类目
     *
     * @param id ID
     * @return 通用代码类目
     */
    @Override
    public CommonType selectCommuneById(Long id) {
        return getById(id);
    }

    /**
     * 查询列表
     *
     * @param commonType 通用代码类目
     * @return 列表
     */
    @Override
    public List<CommonType> selectCommuneList(CommonType commonType) {
        return baseMapper.selectList(new LambdaQueryWrapper<CommonType>()
                .like(ObjectUtil.isNotNull(commonType.getCh()), CommonType::getCh, commonType.getCh())
                .like(ObjectUtil.isNotNull(commonType.getEn()), CommonType::getEn, commonType.getEn()));
    }

    /**
     * 新增
     *
     * @param commonType 通用代码类目
     * @return 结果
     */
    @Override
    public int insertCommune(CommonType commonType) {
        return baseMapper.insert(commonType);
    }

    /**
     * 修改
     *
     * @param commonType 通用代码类目
     * @return 结果
     */
    @Override
    public int updateCommune(CommonType commonType) {
        return baseMapper.updateById(commonType);
    }

    /**
     * 批量删除
     *
     * @param ids 需要删除的ID
     * @return 结果
     */
    @Override
    public int deleteCommuneByIds(Long[] ids) {
        return baseMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除信息
     *
     * @param id ID
     * @return 结果
     */
    @Override
    public int deleteCommuneById(Long id) {
        return baseMapper.deleteById(id);
    }
}
